<?php

class NewUpdateTask extends sfBaseTask
{
    protected function configure()
    {
        $this->addOptions(array(
            new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environement', 'prod'),
            new sfCommandOption('sourceId', null, sfCommandOption::PARAMETER_REQUIRED, '', 0),
        ));
        
        $this->namespace = 'updates';
        $this->name = 'new';
        $this->briefDescription = 'Run a new update for the specified source';
        $this->detailedDescription = '';
    }
    
    protected function execute($arguments = array(), $options = array())
    {
        // Required to allow database queries
        $databaseManager = new sfDatabaseManager($this->configuration);
        
        LogHelper::log('Update requested for sourceId = ' . $options['sourceId']);
        
        $result = SourceUpdates::newRun($options['sourceId']);
        
        LogHelper::log('Finished. Attempted = ' . ($result['attempted'] ? 'true' : 'false') . ', already running = ' . ($result['alreadyRunning'] ? 'true' : 'false') . ', completed = ' . ($result['completed'] ? 'true' : 'false') . ', error = ' . ($result['error'] ? 'true' : 'false'));
        
        LogHelper::log("Done.");
        echo "Done." . PHP_EOL;
    }
}